package org.jeecg.config.miniapp;

import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.api.WxMaUserService;
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;

/**
 * @BelongsProject: jeecg-boot-parent
 * @BelongsPackage: org.jeecg.config.miniapp
 * @Author: mi
 * @CreateTime: 2024-07-10 13:35
 * @Description:
 */
@Configuration
public class WxClientConfig {
    //微信小程序appid
    @Value(value = "${wechat.pay.v3.mobile.app-id}")
    private String appId; //
    //微信小程序密钥
    @Value(value = "${wechat.pay.v3.mobile.app-secret}")
    private String appSecret;



    private WxMaUserService wxMaUserService;

    @PostConstruct
    public void init() {
        //微信小程序
        WxMaDefaultConfigImpl wxMaConfig = new WxMaDefaultConfigImpl();
        wxMaConfig.setAppid(appId);
        wxMaConfig.setSecret(appSecret);

        WxMaService wxMaService = new WxMaServiceImpl();
        wxMaService.setWxMaConfig(wxMaConfig);
        this.wxMaUserService = wxMaService.getUserService();
    }

    @Bean(name = "wxMaUserService")
    public  WxMaUserService wxMaUserService(){
        return this.wxMaUserService;
    }



}
